//
//  SubmitOrderGoodsTableViewCell.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/12.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "SubmitOrderGoodsTableViewCell.h"
#import <UIImageView+WebCache.h>
@interface SubmitOrderGoodsTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *goodImg;//商品图片
@property (weak, nonatomic) IBOutlet UILabel *goodTitleLabel;//商品标题
@property (weak, nonatomic) IBOutlet UILabel *goodPriceLabel;//商品价格
@property (weak, nonatomic) IBOutlet UILabel *goodCountLabel;//商品数量
@property (weak, nonatomic) IBOutlet UILabel *goodType;//商品规格

@property (weak, nonatomic) IBOutlet UILabel *distributionCost;//运费

@property (weak, nonatomic) IBOutlet UILabel *allCost;//订单合计


//适配

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodImgTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodImgLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodImgWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodImgHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodTitleLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodTitleHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceLabelHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceLabelLeading;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodTypeTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodTypeHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodCountTrailing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodCountLabelHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *view1Top;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *distributionCostHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *view2Top;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *allDistributionCostTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *allDistributionCostLabelHeight;

@end


@implementation SubmitOrderGoodsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.goodImgTop.constant = 12 * FitH;
    self.goodImgLeading.constant = 12 * FitW;
    self.goodImgWidth.constant = 97 * FitW;
    self.goodImgHeight.constant = 97 * FitH;
    
    self.goodTitleLeading.constant = 9 * FitW;
    self.goodTitleHeight.constant = 172 * FitH;
    
    self.priceLabelHeight.constant = 12 * FitH;
    self.priceLabelLeading.constant = 10 * FitW;
    
    self.goodTypeTop.constant = 12 * FitH;
    self.goodTypeHeight.constant = 11 * FitH;
    
    self.goodCountTrailing.constant = 27 * FitW;
    self.goodCountLabelHeight.constant = 11 * FitH;
    
    self.view1Top.constant = 10 * FitH;
    self.distributionCostHeight.constant = 14 * FitH;
    
    self.view2Top.constant = 10 * FitH;
    self.allDistributionCostTop.constant = 10 * FitH;
    self.allDistributionCostLabelHeight.constant = 14 * FitH;
    
    
    
//    //关键字高亮
//    NSString *result = [NSString stringWithFormat:@"¥ %@.00",self.model.good_price];
//    NSString *keyWords = @"00";
//    //关键字标红效果
//    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
//    //获取关键字属性
//    NSRange rang = [result rangeOfString:keyWords];
//    //设置关键字属性
//    [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12 * FitH],NSFontAttributeName, nil] range:rang];
//    //添加到label
//    self.allCost.attributedText = attributeString;

    
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(void)setModel:(GoodModel *)model
{
    if (_model != model)
    {
        _model = model;
        
        [self.goodImg sd_setImageWithURL:[NSURL URLWithString:_model.good_img]];
        self.goodTitleLabel.text = _model.good_name;
        self.goodPriceLabel.text = [NSString stringWithFormat:@"¥ %@",_model.good_price_onSale];
        
        
//        //关键字高亮
//        NSString *result = [NSString stringWithFormat:@"¥ %@",_model.good_price_onSale];
//        NSString *keyWords = @"00";
//        //关键字标红效果
//        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
//        //获取关键字属性
//        NSRange rang = [result rangeOfString:keyWords];
//        //设置关键字属性
//        [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12 * FitH],NSFontAttributeName, nil] range:rang];
//        //添加到label
//        self.allCost.attributedText = attributeString;
        
        

        
    }
}

-(void)setUserAllCost:(NSInteger)userAllCost
{
    if (_userAllCost != userAllCost)
    {
        _userAllCost = userAllCost;
        
        //关键字高亮
        NSString *result = [NSString stringWithFormat:@"¥ %zd.00",_userAllCost];
        NSString *keyWords = @".00";
        //关键字标红效果
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
        //获取关键字属性
        NSRange rang = [result rangeOfString:keyWords];
        //设置关键字属性
        [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12 * FitH],NSFontAttributeName, nil] range:rang];
        //添加到label
        self.allCost.attributedText = attributeString;
        
    }
}

-(void)setGoodCount:(NSInteger)goodCount
{
    if (_goodCount != goodCount)
    {
        _goodCount = goodCount;
        
        self.goodCountLabel.text = [NSString stringWithFormat:@"x %zd",_goodCount];
    }
}

-(void)setGoodFreight:(NSInteger)goodFreight
{
    if (_goodFreight != goodFreight)
    {
        _goodFreight = goodFreight;
        
        self.distributionCost.text = [NSString stringWithFormat:@"¥ %zd",_goodFreight];
        
        
    }
}

@end
